/*
 * $Id: unxapi.h,v 1.11 2007-06-22 09:38:05 baconevi Exp $
 */

#ifndef _XP_BAS_UNXAPI_H_
#define _XP_BAS_UNXAPI_H_

#include <xp/types.h>
#include <xp/macros.h>
#include <xp/sys/proc.h>

#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <unistd.h>
#include <limits.h>

#define XP_HND_INVALID (-1)
typedef int xp_hnd_t;

typedef uid_t  xp_uid_t;
typedef gid_t  xp_gid_t;
typedef mode_t xp_mode_t;
typedef off_t  xp_off_t;
typedef struct stat xp_stat_t;

/* maximum path length */
#if /*defined(_SCO_DS) ||*/ !defined(PATH_MAX)
	/*pathconf(_PC_PATH_MAX) returns 1024 on sco osr5. large enough */
	#define XP_PATH_MAX 4096
#else
	#define XP_PATH_MAX (PATH_MAX - 1)
#endif

/* "option" values for xp_wait. can be ORed with each other. */
#define XP_WNOHANG    WNOHANG
#define XP_WUNTRACED  WUNTRACED

#ifdef WIFEXITED
	#define XP_WIFEXITED(x) (WIFEXITED(x))
#endif
#ifdef WEXITSTATUS
	#define XP_WEXITCODE(x) (WEXITSTATUS(x))
#endif
#ifdef WIFSIGNALED
	#define XP_WIFSIGNALED(x) (WIFSIGNALED(x))
#endif
#ifdef WTERMSIG
	#define XP_WTERMSIG(x) (WTERMSIG(x))
#endif
#ifdef WIFSTOPPED
	#define XP_WIFSTOPPED(x) (WIFSTOPPED(x))
#endif
#ifdef WSTOPSIG
	#define XP_WSTOPSIG(x) (WSTOPSIG(x))
#endif
#ifdef WCOREDUMP
	#define XP_WCOREDUMP(x) (WCOREDUMP(x))
#endif

#ifdef __cplusplus
extern "C" {
#endif

xp_uid_t xp_getuid (void);
xp_uid_t xp_geteuid (void);
xp_gid_t xp_getgid (void);
xp_gid_t xp_getegid (void);

xp_pid_t xp_setsid (void);
xp_pid_t xp_getpid (void);
xp_pid_t xp_getppid (void);

int xp_setpgid (xp_pid_t pid, xp_pid_t pgid);
xp_pid_t xp_getpgid (xp_pid_t pid);
int xp_setpgrp (void);
xp_pid_t xp_getpgrp (void);

xp_pid_t xp_fork (void);
xp_pid_t xp_wait (xp_pid_t pid, int *status, int options);

int xp_pipe (int pfd[2]);

#ifdef __cplusplus
}
#endif

#endif
